package org.point.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductTypeDao;
import org.point.domain.CreditsType;
import org.point.domain.ProductType;
import org.point.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: ProductTypeServiceImpl
 * @Description: TODO(商品分类业务实现类)
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01
 *
 */
@Service("productTypeService")
public class ProductTypeServiceImpl extends BaseServiceImpl<ProductType, Serializable> implements ProductTypeService {

	@Autowired
	private ProductTypeDao dao;

	public List<ProductType> findProList(Map<String, Object> map) {
		List<ProductType> records = dao.searchForMem(map);
		return records;
	}

	public List<ProductType> findProList(DoPage<ProductType> page) {
		List<ProductType> records = dao.searchForMem(page);
		return records;
	}

	public List<ProductType> findProList(Integer currentPage, Map<String, Object> map) {
		DoPage<ProductType> page = new DoPage<ProductType>();
		dao.searchForMem(page);
		return null;
	}

	public Integer countProForPage(DoPage<ProductType> page) {
		Integer result = dao.searchForMemCount(page);
		return result;
	}
	
	public DoPage<ProductType> searchCRForPage(DoPage<ProductType> page) {
		List<ProductType> records = dao.searchForMem(page);
		Integer totalRecords = dao.searchForMemCount(page);
		page.setList(records);
		page.setTotalRecords(totalRecords);
		return page;
	}

	public Integer insertPro(ProductType record ,String pyt_code) {
		
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		if(record.getId()!=null){
			map.put("del_id",record.getId());
			Integer del  = dao.delProTy(map);
			Integer insert  = dao.insertPT(record);
			if(insert+del>1){
				result = 1;
		    }
		}else{
			record.setStatus(new Byte("1"));
			record.setProductTypeId(pyt_code);
			result = dao.insertPT(record);
		}
		return result;
	}

	public Integer editProForStatus(Map<String, Object> map) {
		Integer result = dao.updStatus(map);
		return result;
	}

	public Integer editPtIfo(ProductType record) {
		// TODO 修改商品分类信息
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("delFlag", 0);
		map.put("productTypeId", record.getProductTypeId());
		// 修改积分规则分类删除状态
		Integer delRsult = dao.delProTy(map);
		// 修改积分规则分类删除状态成功，则新增积分规则分类
		if(delRsult == 1){
			result = dao.insert(record);
		}
		return result;
	}

	public ProductType searchForId(Map<String, Object> map) {
		// TODO 根据商品ID查找
		return dao.searchForId(map);
	}

	public Integer delProTy(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return dao.delProTy(map);
	}

}
